package com.winit.rabbitmq;


import com.alibaba.fastjson.JSONObject;
import com.winit.task.model.UCloudTask;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

@Component
public class MessageHandle {



    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = RabbitMqConsts.NODE_QUEUE, durable = "true"),
            exchange = @Exchange(value = RabbitMqConsts.NODE_EXCHANGE, ignoreDeclarationExceptions = "true"),
            key = RabbitMqConsts.NODE_ROUTE)
    )
    public void handleMessage(@Payload MqMessage msg){
        System.err.println(msg);
        if(MessageType.TASK.equals(msg.getMessageType())){
            Object payLoad = msg.getPayLoad();
            System.err.println(payLoad);
            String json = JSONObject.toJSON(payLoad).toString();
            UCloudTask uCloudTask = JSONObject.parseObject(json, UCloudTask.class);
            System.err.println(uCloudTask);
        }
    }
}
